<?php

namespace app\admin\model\activity;

use app\admin\model\User;
use app\common\model\Address;
use app\common\model\Category;
use think\Model;


class AwardCeremony extends Model
{
    // 表名
    protected $name = 'award_ceremony';

    // 自动写入时间戳字段
    protected $autoWriteTimestamp = 'integer';

    // 定义时间戳字段名
    protected $createTime = 'createtime';
    protected $updateTime = 'updatetime';
    protected $deleteTime = false;

    // 时间属性
    protected $type = [
        'createtime' => 'datetime:Y-m-d H:i:s',
        'updatetime' => 'datetime:Y-m-d H:i:s'
    ];

    // 追加属性
    protected $append = [

    ];

    protected function getContentAttr($value)
    {
        return $value ? json_decode($value, true) : [];
    }

    public function activity()
    {
        return $this->belongsTo('app\admin\model\Activity', 'activity_id', 'id', [], 'LEFT')->setEagerlyType(0);
    }


    public function goods()
    {
        return $this->belongsTo('app\admin\model\Goods', 'goods_id', 'id', [], 'LEFT')->setEagerlyType(0);
    }

    public function category()
    {
        return $this->belongsTo(Category::class, 'cate_id', 'id', [], 'LEFT')->setEagerlyType(0);
    }

    public function user()
    {
        return $this->belongsTo(User::class, 'user_id', 'id', [], 'LEFT')->setEagerlyType(0);
    }

    public function address()
    {
        return $this->belongsTo(Address::class, 'address_id', 'id', [], 'LEFT')->setEagerlyType(0);
    }
}
